local skel = fk.CreateSkill {
  name = "lb__kuaiyu",
  max_branches_use_time = {
    ["slash"] = {
      [Player.HistoryRound] = 1
    },
  }
}

Fk:loadTranslationTable {
  ["lb__kuaiyu"] = "快雨",
  [":lb__kuaiyu"] = "每轮限一次，当你成为其他角色使用牌的目标时，你可以重铸任意张【杀】并选择至多等量名角色，依次视为对这些角色使用【杀】，然后你可以转换<a href=':lb__zhijian'><font color='red'>〖智剑〗</font></a>。",

  ["#lb__kuaiyu"] = "快雨：你可以重铸任意张【杀】并视为使用【杀】",
  ["#lb__kuaiyu-ask"] = "快雨：你可以依次视为对至多 %arg 名角色使用【杀】",

  ["lb__zhijian-jr"] = "快雨：你可以进入〖智剑〗",
  ["lb__zhijian-tl"] = "快雨：你可以脱离〖智剑〗",

  ["$lb__kuaiyu1"] = "剑，随我心。",
  ["$lb__kuaiyu2"] = "万剑，天来！",
  ["$lb__kuaiyu3"] = "试探就到此为止了。",
}

skel:addEffect(fk.TargetConfirming, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and data.from and data.from ~= player and
        player:usedSkillTimes(skel.name, Player.HistoryRound, "slash") == 0 and
        table.find(player:getCardIds("h"), function(id)
          return Fk:getCardById(id).trueName == "slash"
        end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local cards = room:askToCards(player, {
      min_num = 1,
      max_num = 999,
      prompt = "#lb__kuaiyu",
      skill_name = "lb__kuaiyu",
      include_equip = false,
      pattern = "slash",
    })
    event:setCostData(self, { cards = cards })
    return #cards > 0
  end,
  on_use = function(self, event, target, player, data)
    player:addSkillBranchUseHistory(skel.name, "slash")
    local room = player.room
    player:broadcastSkillInvoke(skel.name, 3) --3
    room:notifySkillInvoked(player, skel.name, "offensive")
    local cards = event:getCostData(self).cards
    room:recastCard(cards, player, skel.name)
    local c = Fk:cloneCard("slash")
    local ts = c:getAvailableTargets(player, { bypass_distances = true })
    if #ts > 0 then
      local t = room:askToChoosePlayers(player, {
        targets = ts,
        min_num = 1,
        max_num = #cards,
        prompt = "#lb__kuaiyu-ask:::" .. #cards,
        skill_name = skel.name,
      })
      if #t > 0 then
        player:broadcastSkillInvoke(skel.name, (#t > 1) and 2 or 1)
        room:sortByAction(t)
        for _, p in ipairs(t) do
          room:useVirtualCard("slash", nil, player, { p }, skel.name, true)
        end
      end
    end
    if player:hasSkill("lb__zhijian", true) and room:askToSkillInvoke(player, {
          skill_name = skel.name,
          prompt = player:getSwitchSkillState("lb__zhijian", true) == fk.SwitchYang and "lb__zhijian-tl" or "lb__zhijian-jr" }) then
      local zhijian = Fk.skills["lb__zhijian"] --- @cast zhijian TriggerSkill
      room:useSkill(player, zhijian, function()
        return zhijian:use(event, target, player, { extra_data = { lb__kuaiyu = true } })
      end)
    end
  end,
}, { check_skill_limit = true})

return skel
